#include "ModelPrimitive.h"
ModelPrimitive::ModelPrimitive(){
	//Set default material properties
	ZeroMemory(&mMaterial, sizeof(D3DMATERIAL9));    // clear out the struct for use
    mMaterial.Diffuse.r = 1.0f;
    mMaterial.Diffuse.g = 1.0f;
    mMaterial.Diffuse.b = 1.0f;	
    mMaterial.Diffuse.a = 1.0f;
	mMaterial.Ambient.r = 1.0f;    // set the material to full red
	mMaterial.Ambient.g = 1.0f;    // set the material to full green
	mMaterial.Ambient.b = 1.0f;    // set the material to full blue	
	mMaterial.Ambient.a = 1.0f;

	//GetMesh()->Release();
	SetMesh(NULL);
}

void ModelPrimitive::LoadContent(LPDIRECT3DDEVICE9 d3ddev){
	
}


void ModelPrimitive::Draw(LPDIRECT3DDEVICE9 d3ddev){
	D3DXMATRIX* mTransforms = GetTransMatrix();
	d3ddev->SetTransform(D3DTS_WORLD, mTransforms);
	d3ddev->SetMaterial(&mMaterial);
	mMeshPrim->DrawSubset(0);;
}


void ModelPrimitive::SetTeapot(LPDIRECT3DDEVICE9 d3ddev,LPD3DXBUFFER *ppAdjacency){
	D3DXCreateTeapot(d3ddev, &mMeshPrim, ppAdjacency); 
}
	//ppAdjacency should be null, 
void ModelPrimitive::SetSphere(LPDIRECT3DDEVICE9 d3ddev,
						FLOAT Radius,
                        UINT Slices,
                        UINT Stacks,
						LPD3DXBUFFER *ppAdjacency){

	D3DXCreateSphere(d3ddev, Radius, Slices, Stacks, &mMeshPrim, ppAdjacency);  
}
void ModelPrimitive::SetBox(LPDIRECT3DDEVICE9 d3ddev,
						float Width,
						float Height,
						float Depth,
						LPD3DXBUFFER *ppAdjacency){
	D3DXCreateBox(d3ddev, Width, Height, Depth, &mMeshPrim, ppAdjacency); 
}
void ModelPrimitive::SetCyclinder(LPDIRECT3DDEVICE9 d3ddev,
						float Radius1,
                        float Radius2,
						float Length,
						UINT Slices,
						UINT Stacks,
						LPD3DXBUFFER *ppAdjacency){
	D3DXCreateCylinder( d3ddev,Radius1,Radius2, Length,Slices,Stacks,
                           &mMeshPrim, ppAdjacency);
}

D3DMATERIAL9* ModelPrimitive::GetMaterial(){
	return  &mMaterial;
}

void ModelPrimitive::SetMaterial(D3DMATERIAL9* pMat){
	mMaterial = *(pMat);
}

void ModelPrimitive::Release(){
	mMeshPrim->Release();
}